

/******************************************************************************

  Copyright (C), 2001-2011, DCN Co., Ltd.

 ******************************************************************************
  File Name 	: timer.c
  Version		: Initial Draft
  Author		: Hust
  Created		: 2022/11/7
  Last Modified :
  Description	: timer file head
  Function List :
			  CheckTimer
			  HAL_SYSTICK_Callback
			  ResetTimer
			  SetTimer
  History		:
  1.Date		: 2022/11/7
	Author		: Hust
	Modification: Created file

******************************************************************************/

/*----------------------------------------------*
 * include headfile 							*
 *----------------------------------------------*/

/*----------------------------------------------*
 * variables typedef							 *
 *----------------------------------------------*/

/*----------------------------------------------*
 * macros										*
 *----------------------------------------------*/
#define TIMER_SIZE				3
#define TEMPO_10MS				10

/*----------------------------------------------*
 * constants									*
 *----------------------------------------------*/

/*----------------------------------------------*
 * external variables							*
 *----------------------------------------------*/

/*----------------------------------------------*
 * project-wide global variables				*
 *----------------------------------------------*/
unsigned short	gTickCnt = 0;
unsigned char	gTempo_10ms = 0;

/*----------------------------------------------*
 * module-wide global variables 				*
 *----------------------------------------------*/
static unsigned short int sTimerCnt[TIMER_SIZE];
static unsigned char sTimeOut[TIMER_SIZE];

/*----------------------------------------------*
 * external routine prototypes					*
 *----------------------------------------------*/

/*----------------------------------------------*
 * internal routine prototypes					*
 *----------------------------------------------*/

/*----------------------------------------------*
 * routines' implementations					*
 *----------------------------------------------*/

/*****************************************************************************
 Prototype	  : SetTimer
 Description  : set a timer parameter
 Input		  : uint16_t sec
 Output 	  : None
 Return Value : void
 Calls		  : 
 Called By	  : 
 
  History		 :
  1.Date		 : 2022/11/7
	Author		 : Hust
	Modification : Created function

*****************************************************************************/
void SetTimer(unsigned char index, unsigned short sec)
{
	sTimerCnt[index]	= sec;
}


void ResetTimer(unsigned char index)
{
	sTimerCnt[index]	= 0;
}



inline char CheckTimer(char timer_index)
{
	return sTimerCnt[timer_index] ? 1: 0;
}


inline void HAL_SYSTICK_Callback(void)
{
	if (sTimerCnt[0])
		sTimerCnt[0] --;

	if (sTimerCnt[1])
		sTimerCnt[1] --;

	if (sTimerCnt[2])
		sTimerCnt[3] --;

	gTickCnt++;

	if (gTickCnt > TEMPO_10MS)
	{
		gTempo_10ms 		= true;
		gTickCnt			= 0;
	}

}


